package com.spc.car.data.service.org.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spc.car.data.entity.org.OrgPersonnelInformation;
import com.spc.car.data.mapper.org.OrgPersonnelInformationMapper;
import com.spc.car.data.domain.org.po.SavePersonnelInformPO;
import com.spc.car.data.service.org.OrgPersonnelInformationService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2020-03-30
 */
@Service
public class OrgPersonnelInformationServiceImpl extends ServiceImpl<OrgPersonnelInformationMapper, OrgPersonnelInformation> implements OrgPersonnelInformationService {

    @Override
    public int saveOrgPersonnelInformation(SavePersonnelInformPO savePersonnelInformPO) {
            OrgPersonnelInformation orgPersonnelInformation = new OrgPersonnelInformation();
            BeanUtils.copyProperties(savePersonnelInformPO,orgPersonnelInformation);
            if (saveOrUpdate(orgPersonnelInformation)){
                return 1;
            }
            return 0;
    }

    @Override
    public boolean uniquePersonCode(String personCode, Integer id) {
        OrgPersonnelInformation information = getOne(new QueryWrapper<OrgPersonnelInformation>()
                .eq("person_code", personCode)
                .ne(null != id,"id", id)
        );
        if (ObjectUtils.isNotNull(information)){
            return false;
        }
        return true;
    }

    @Override
    public OrgPersonnelInformation getPersonnelInform(String personCode) {
        return getOne(new QueryWrapper<OrgPersonnelInformation>()
                .eq("person_code", personCode)
        );
    }
}
